const MongoClient = require('mongodb').MongoClient;
const { MONGO_CONF } = require('../config/db')

// 连接mongo
module.exports = async () => {
  const url = `mongodb://${MONGO_CONF.host}:${MONGO_CONF.port}/${MONGO_CONF.database}`
  let db
  try {
    db = await MongoClient.connect(url, { useNewUrlParser: true })
    return db.db('blogs')
  } catch (e) {
    console.log(e.toString())
  }
}
